﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using WinnerCMS.Model;

namespace WinnerCMS.Data.Mapping
{
    public partial class CoreMap
        : System.Data.Entity.ModelConfiguration.EntityTypeConfiguration<WinnerCMS.Model.Core>
    {
        public CoreMap()
        {
            ToTable("Cores");
            // keys
            HasKey(t => t.Id);

            // Properties
            Property(t => t.Id)
                
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
                .IsRequired();
            Property(t => t.CategoryId)
                
                .IsRequired();
            Property(t => t.ContentTitle)
                
                .HasMaxLength(100)
                .IsRequired();
            Property(t => t.Brief)
                .HasMaxLength(255)
                .IsRequired();
            Property(t => t.CssClass)
                .IsUnicode(false)
                .HasMaxLength(50)
                .IsOptional();
            Property(t => t.Editor)
                
                .HasMaxLength(50)
                .IsRequired();
            Property(t => t.Hits)
                
                .IsRequired();
            Property(t => t.DayHits)
                
                .IsRequired();
            Property(t => t.WeekHits)
                
                .IsRequired();
            Property(t => t.MonthHits)
                
                .IsRequired();
            Property(t => t.IncludePic)
                
                .IsRequired();
            Property(t => t.PicUrl)
                .IsUnicode(false)
                .HasMaxLength(255)
                .IsRequired();
            Property(t => t.Stars)
                
                .IsRequired();
            Property(t => t.IsSlide)
                
                .IsRequired();
            Property(t => t.IsHeadline)
                
                .IsRequired();
            Property(t => t.IsElite)
                
                .IsRequired();
            Property(t => t.IsOnTop)
                
                .IsRequired();
            Property(t => t.Rank)
                
                .IsRequired();
            Property(t => t.PointNum)
                
                .IsRequired();
            Property(t => t.AllowComment)
                
                .IsRequired();
            Property(t => t.CreateTime)
                
                .IsRequired();
            Property(t => t.UpdateTime)
                
                .IsRequired();
            Property(t => t.LastHitTime)
                
                .IsOptional();
            Property(t => t.TemplateFileName)
                .IsUnicode(false)
                .HasMaxLength(255)
                .IsRequired();
            Property(t => t.CommentQuantity)
                
                .IsRequired();
            Property(t => t.CommentScore)
                
                .IsRequired();

           
            // Relationships

            HasRequired(x => x.Category)
                .WithMany(x => x.Cores)
                .HasForeignKey(x => x.CategoryId)
                .WillCascadeOnDelete(false);

            HasMany(t => t.DeputyCategoryes)
                .WithMany(t => t.DeputyCores);

            HasMany(t => t.Specials)
                .WithMany(t => t.Cores);

            HasMany(t => t.TagsInfos)
                .WithMany(t => t.Cores);


            //Map<Core>(x => x.ToTable("Cores"));
            Map<Article>(x => x.ToTable("Articles"));
            Map<Soft>(x => x.ToTable("Softs"));
            Map<Photo>(x => x.ToTable("Photos"));
            Map<Goods>(x => x.ToTable("Goods"));

            //InitializeMapping();
        }
    }
}

